{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false,
    "slideshow": {
     "slide_type": "-"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYEAAADgCAYAAADlhtpvAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAG5VJREFUeJzt3W+MVtWdB/DvD5EOA4J0FQYZRwZbareJASLUpptIttst\nNmmVaHb1TUs36ZrN+m7TtZs2btY3WzdpsmmbptvEkPKicV9sSqktrtbWTci2CgXaRRSpWBUYEJUZ\n/g4z4tkX83D93dPn3jn3/7n3fD8J8TzznOfe81xn7j2/81eMMSAiojDNaboARETUHD4EiIgCxocA\nEVHA+BAgIgoYHwJERAHjQ4CIKGClPARE5DEROSkiv0vJ8y0ROSwi+0VkTRnnJSKiYsqKBLYC+EzS\nmyJyJ4CbjTEfBvAAgO+VdF4iIiqglIeAMWYXgNMpWe4CsK2X9zkAi0VkWRnnJiKi/OrqE1gB4A31\n+ljvZ0RE1KC5TRfAJiJcx4KIKCNjjOT5XF0PgWMAblSvh3s/I2otkVx/c4mMMaUfM4k+j05fddVV\nsXzvvfdelL766quj9NTU1B/lq7P8V3Dts+LKbA6S3r9+dgD4AgCIyO0Axo0xJ0s8NxER5VBKJCAi\nPwSwEcCfiMjrAP4ZwDwAxhjzfWPMz0TksyLyewDnAXypjPMS1anuWm6ZXMuua/4A8IEPfCBKT05O\nRmnWwLtDfPufyT4B8lXVD4Eqm1PSjpvUNAS4PwSMMWwOapjvfQJENAsfIg37pmq3/ScRkaj8dd6Y\n9TXjAyEfLhtBRBQwRgJEKXyoneeVp+xz5sTrhXq0kN1fQN3ASICIKGDsGCaytLn2r6V1+Gq689eu\n7evIYP78+VH69OnkVWJ8uaf4Uo665O0YZiRARBQw9glQ8LpS809jf0ddS56eno7Sw8PDsXwDAwNR\nemxszOl41C6MBIiIAsY+AQpelyKBpH6AefPmxfLp2r9u97906V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uATgdQBfKuPac7IYEVHAfBodRERENeNDgIgoYHwIEBEFjA8BIqKA8SFARBQwPgSI\niALGhwARUcD+H/nm+6Md8e9iAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x10cdf7400>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Interactive version of the \"Mandelbrot Set\" - solution to challenge in \n",
    "# \"Doing Math with Python\", chapter 6\n",
    "%matplotlib inline\n",
    "'''\n",
    "mandelbrot.py\n",
    "\n",
    "Draw a Mandelbrot set\n",
    "\n",
    "Using \"Escape time algorithm\" from:\n",
    "http://en.wikipedia.org/wiki/Mandelbrot_set#Computer_drawings\n",
    "\n",
    "Thanks to http://www.vallis.org/salon/summary-10.html for some important\n",
    "ideas for implementation.\n",
    "\n",
    "'''\n",
    "\n",
    "from ipywidgets import interact\n",
    "import ipywidgets as widgets\n",
    "\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "import matplotlib.cm as cm\n",
    "\n",
    "# Subset of the complex plane we are considering\n",
    "x0, x1 = -2.5, 1\n",
    "y0, y1 = -1, 1\n",
    "\n",
    "def initialize_image(x_p, y_p):\n",
    "    image = []\n",
    "    for i in range(y_p):\n",
    "        x_colors = []\n",
    "        for j in range(x_p):\n",
    "            x_colors.append(0)\n",
    "        image.append(x_colors)\n",
    "    return image\n",
    "\n",
    "def mandelbrot_set(n, max_iterations):\n",
    "    image = initialize_image(n, n)\n",
    "    \n",
    "    # Generate a set of equally spaced points in the region\n",
    "    # above\n",
    "    dx = (x1-x0)/(n-1)\n",
    "    dy = (y1-y0)/(n-1)\n",
    "    x_coords = [x0 + i*dx for i in range(n)]\n",
    "    y_coords = [y0 + i*dy for i in range(n)]\n",
    "\n",
    "    for i, x in enumerate(x_coords):\n",
    "        for k, y in enumerate(y_coords):\n",
    "            z1 = complex(0, 0)\n",
    "            iteration = 0\n",
    "            c = complex(x, y)\n",
    "            while (abs(z1) < 2  and iteration < max_iterations):\n",
    "                z1 = z1**2 + c\n",
    "                iteration += 1\n",
    "            image[k][i] = iteration\n",
    "    return image\n",
    "\n",
    "def draw_mandelbrot(n, max_iterations):\n",
    "    image = mandelbrot_set(n, max_iterations)\n",
    "    plt.imshow(image, origin='lower', extent=(x0, x1, y0,y1),\n",
    "               cmap=cm.Greys_r, interpolation='nearest')\n",
    "    plt.show()\n",
    "    \n",
    "\n",
    "# Allow interaction via the interact() function and an Integer slider widget\n",
    "i = interact(draw_mandelbrot, \n",
    "             n=widgets.IntSlider(min=100, max=600,step=1,value=10), \n",
    "             max_iterations=widgets.IntSlider(min=100, max=10000,step=1,value=10),\n",
    "             # This keyword argument adds a button so that the drawing happens\n",
    "             # only when the button is clicked\n",
    "             __manual=True\n",
    "             )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
